package com.attendance.sz.utils;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;

/**
 * Application version related tools
 */
public class Version {

	/**
	 *Gets the version number
	 *
	 * @return
	 */
	public static String getVersionName()
	{
		Context context = MyApplication.getAppContext();
	    PackageManager packageManager = context.getPackageManager();  
	    //GetPackageName () is your current class package name, 0 stands for is to get version information  
	    PackageInfo packInfo;
		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
		
			return packInfo.versionName;   
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return "";
		}
	}
	
	/**
	 * The App for current versionCode (from 1 started), if not find (NameNotFoundException), return zero
	 * @Title: getVersionCode
	 * @Description: TODO
	 * @return
	 */
	public static int getVersionCode()
	{
		Context context = MyApplication.getAppContext();
	    PackageManager packageManager = context.getPackageManager();  
	    //GetPackageName () is your current class package name, 0 stands for is to get version information  
	    PackageInfo packInfo;
		try {
			packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
			
			return packInfo.versionCode;   
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return 0;
		}
	}
	
	/**
	 * Get device id (IMEI number)
	 *
	 * @return
	 */
//	public static String getDeviceID()
//	{
//		Context context = MyApplication.getAppContext();
//		return ((TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE)).getDeviceId();
//	}
	
//	public static String GetDeviceId(Context context)
//	{
//		String strDeviceId;
//	    TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE); 	
//	 	strDeviceId=tm.getDeviceId();
//	 	if(strDeviceId==null||strDeviceId.equals(""))
//	 	{
//	 	   strDeviceId=Secure.getString(context.getApplicationContext().getContentResolver(), Secure.ANDROID_ID); 
//	 	}
//	   
//		//return strDeviceId;
//		
//		return "05600115090100100006";
//	}
	
	public static String GetLocalIp()
	{
		if(Session.getLocalIp().equals("0"))
		{
			return Constants.Local_Ip;
		}
		
		return Session.getLocalIp();
	}
	
	public static String GetLocalNetMask()
	{
		if(Session.getLocalNetMask().equals("0"))
		{
			return Constants.Local_Net_Mask;
		}
		
		return Session.getLocalNetMask();
	}
	
	public static String GetLocalGetWay()
	{
		if(Session.getLocalGetWay().equals("0"))
		{
			return Constants.Local_Get_Way;
		}
		
		return Session.getLocalGetWay();
	}
	
	public static String GetSeverIp()
	{
		if(Session.getServerIp().equals("0"))
		{
			return Constants.Sever_Ip;
		}
		
		return Session.getServerIp();
	}
	
	public static String GetSeverPort()
	{
		if(Session.getServerPort().equals("0"))
		{
			return Constants.Server_Port;
		}
		
		return Session.getServerPort();
	}
	
	public static String GetOverTime()
	{
		if(Session.getOverTime().equals("0"))
		{
			return Constants.Over_Time;
		}
		
		return Session.getOverTime();
	}
	
	public static String GetIntervalTime()
	{
		if(Session.getIntervalTime().equals("0"))
		{
			return Constants.Interval_Time;
		}
		
		return Session.getIntervalTime();
	}
	
	public static String GetMachineNo()
	{
		if(Session.getMachineNo().equals("0"))
		{
			return Constants.Machine_No;
		}
		
		return Session.getMachineNo();
	}
	
	public static String GetDownUrl()
	{
		if(Session.getDownUrl().equals("0"))
		{
			return Constants.Down_Url;
		}
		
		return Session.getDownUrl();
	}
	public static String GetDownTiem()
	{
		if(Session.getDownUrl().equals("0"))
		{
			return Constants.DownTiem_Url;
		}

		return Session.getDownUrlTiem();
	}
	
	public static String GetSeverLogIp()
	{
		if(Session.getServerLogIp().equals("0"))
		{
			return Constants.SeverLog_Ip;
		}
		
		return Session.getServerLogIp();
	}
	
	public static String GetSeverLogPort()
	{
		if(Session.getServerLogPort().equals("0"))
		{
			return Constants.ServerLog_Port;
		}
		
		return Session.getServerLogPort();
	}
	
}
